import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;

/**
 * Created by kroc on 2016/1/04.
 */
public class GetHttp {
    public JSONObject getjson(String URL) {
        String content = "";
        try {
            HttpClient httpClient = HttpClients.createDefault();
            HttpGet req = new HttpGet(URL);
            req.addHeader("Accept", "application/json,text/javascript, */*; q=0.01");
            req.addHeader("Accept-Encoding", "gzip,deflate,sdch");
            req.addHeader("Accept-Language", "zh-CN,zh,q=0.8");
            req.addHeader("Accept-Type", "text/html;charset=UTF-8");
            req.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36");
            HttpResponse rep = httpClient.execute(req);
            HttpEntity repEntity = rep.getEntity();
            content = EntityUtils.toString(repEntity);
        }
        catch (Exception e) {
        }
        JSONObject jsonObject = new JSONObject(content);
        return jsonObject;
    }
}

